#include<iostream>
#include<vector>
#include<queue>
#include<cstring>
#include<cmath>
#include<map>
#include<set>
#include<cstdio>
#include<algorithm>
#define debug(a) cout<<#a<<"="<<a<<endl;
using namespace std;
const int maxn=1e5+1000;
typedef long long LL;
inline LL read(){LL x=0,f=1;char ch=getchar();	while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;}
LL dp[maxn];
struct P{
   LL a,b,h;
}p[maxn];
bool cmp(P A,P B){
     if(A.b==B.b) return A.a>B.a;
     return A.b>B.b;
}
struct Node{
    LL a,val;
    friend bool operator<(struct Node A,struct Node B){
       return A.val<B.val;
    }
};priority_queue<Node>que;
int main(void){
    LL n;n=read();
    for(LL i=1;i<=n;i++){
        p[i].a=read();p[i].b=read();p[i].h=read();
    }
    sort(p+1,p+1+n,cmp);
    que.push({0,0});
    LL ans=0;
    for(LL i=1;i<=n;i++){
        while(!que.empty()&&que.top().a>=p[i].b) que.pop();
        Node now=que.top();
        dp[i]=max(dp[i],now.val+p[i].h);
        que.push({p[i].a,dp[i]});
        ans=max(ans,dp[i]);
    }
    cout<<ans<<"\n";
   	return 0;
}
